package com.info.zhiduoduo.repository.mapper.notice;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.info.zhiduoduo.repository.entity.notice.NoticeReadRecord;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface NoticeReadRecordMapper extends BaseMapper<NoticeReadRecord> {


    @Insert(" <script>" +
            " insert into zdd_notice_read_record " +
            " (notice_id,user_id,user_type) " +
            " values " +
            " <foreach collection=\"list\" item=\"item\" separator=\",\">" +
            " (#{item.noticeId},#{item.userId},#{item.userType})" +
            " </foreach>" +
            " </script>")
    void insertBatch(List<NoticeReadRecord> list);

    //查询企业所有已读公告
    @Select("SELECT n.id as noticeId " +
            " from zdd_notice n " +
            " left join zdd_notice_read_record nr on n.id = nr.notice_id " +
            " where n.type in(${noticeType})" +
            " and user_id = #{compid} " +
            " and nr.user_type = #{userType} " +
            " and nr.id is not null")
    List<NoticeReadRecord> selectCompAllRead(int compid, String noticeType, int userType);

    //查询企业所有未读公告
    @Select("SELECT n.id as noticeId,#{compid} as userId,2 as userType" +
            " from zdd_notice n " +
            " left join zdd_notice_read_record nr on n.id = nr.notice_id and user_type = 2 " +
            " where n.notice_type in(${noticeType}) " +
            " and user_id = #{compid} " +
            " and nr.id is null ")
    List<NoticeReadRecord> selectCompAllUnRead(int compid, String noticeType);
}
